package com.ilovepostcard.controller.server;

public class QueryItem {

    private static final String __charset = "utf-8";

    private String key;

    private String value;

    private boolean needEncode;

    public static QueryItem createQueryItem(String key, String value) {
        return new QueryItem(key, value, false);
    }

    public static QueryItem createURLEncodeQueryItem(String key, String value) {
        return new QueryItem(key, value, true);
    }

    private QueryItem(String key, String value, boolean needEncode) {
        super();
        this.key = key;
        this.value = value;
        this.needEncode = needEncode;
    }

    public String toString() {
        String _value = value;
        if (needEncode) {
            try {
                _value = java.net.URLEncoder.encode(_value, __charset);
            } catch (Exception e) {
                // TODO: handle exception
            }
        }
        return key + "=" + _value;
    }
}
